package com.xunji.xunji.module.account.ui.activity;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.huanxiao.base.base.BaseActivity;
import com.huanxiao.base.util.AlertDialogUtil;
import com.huanxiao.base.view.SettingLayout;
import com.xunji.xunji.R;
import com.xunji.xunji.module.account.bean.UserInfo;
import com.xunji.xunji.module.account.controller.UserAccount;

/**
 * Created by Paul on 2017/2/2.
 */

public class PersonalActivity extends BaseActivity implements View.OnClickListener {

    private ImageView ivAvatar;
    private ImageView ivCover;
    private SettingLayout slNumber;
    private SettingLayout slNickname;
    private SettingLayout slSex;
    private SettingLayout slPhone;
    private SettingLayout slIdCard;


    private String[] changeHead = {"更换头像"};
    private String[] changeCover = {"更换封面"};
    private String[] changeSex = {"男","女"};

    public static void start(Context context) {
        Intent starter = new Intent(context, PersonalActivity.class);
        context.startActivity(starter);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_personal;
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    public void initBundleExtras(Bundle extras) {

    }

    @Override
    protected void initView() {

        ivAvatar = fvById(R.id.iv_avatar);
        ivCover = fvById(R.id.iv_cover);
        slNumber = fvById(R.id.sl_number);
        slNickname = fvById(R.id.sl_nickname);
        slSex = fvById(R.id.sl_sex);
        slPhone = fvById(R.id.sl_phone);
        slIdCard = fvById(R.id.sl_idcard);
    }

    @Override
    protected void initListener() {
//        slPhone.setOnClickListener(this);

        slNickname.setOnClickListener(this);
        slSex.setOnClickListener(this);

        ivCover.setOnClickListener(this);
        ivAvatar.setOnClickListener(this);

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        UserInfo userInfo = UserAccount.getInstance().getUserInfo();
        if (userInfo!=null){
            slNickname.setSubTitle(userInfo.getNickname());
            slPhone.setSubTitle(userInfo.getPhone());
            slSex.setSubTitle(userInfo.getGender()==0?"男":"女");
            slIdCard.setSubTitle(userInfo.getIdCard()!=null?userInfo.getIdCard():"未设置");
            slNumber.setSubTitle(userInfo.getUserId());
        }


    }

    @Override
    protected boolean isBindEventBus() {
        return false;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.sl_nickname:

                break;

            case R.id.sl_sex:
                AlertDialogUtil.createActionSheet(this, changeSex, new AlertDialogUtil.OnFinishClickListener() {
                    @Override
                    public void onFinishListener(int position, String strs, Dialog dialog) {

                    }
                }).show();
                break;

            case R.id.iv_avatar:
                AlertDialogUtil.createActionSheet(this, changeHead, new AlertDialogUtil.OnFinishClickListener() {
                    @Override
                    public void onFinishListener(int position, String strs, Dialog dialog) {
                        if (position == 0) {

                        }
                    }
                }).show();
                break;

            case R.id.iv_cover:
                AlertDialogUtil.createActionSheet(this, changeCover, new AlertDialogUtil.OnFinishClickListener() {
                    @Override
                    public void onFinishListener(int position, String strs, Dialog dialog) {
                        if (position == 0) {

                        }
                    }
                }).show();

                break;
        }
    }


    @Override
    protected void onRightNavigationClick() {
        super.onRightNavigationClick();
        SettingsActivity.start(this);
    }
}
